<style>
    .panel-heading a{
        margin-left: 10px;
        cursor: default;
    }
    .panel-heading a span{
        display: inline-block;
        width: 10px;
        height: 10px;
        border: 1px solid black;
    }
    .panel-heading a span.gray,#formorder table tbody tr td.gray{
        background-color: gray;
        border: 1px solid gray;
        color: #FFF0F0;
    }
    .panel-heading a span.blue,#formorder table tbody tr td.blue{
        background-color: #5bc0de;
        border: 1px solid #5bc0de;
        color: #FFF0F0;
    }
    .panel-heading a span.red,#formorder table tbody tr td.red{
        background-color: #FF4444;
        border: 1px solid #FF4444;
        color: #FFF0F0;
    }
    .panel-heading a span.zi,#formorder table tbody tr td.zi{
        background-color: #A244FF;
        border: 1px solid #A244FF;
    }.panel-heading a span.fff,#formorder table tbody tr td.fff{
        background-color: #fff;
    }
    #formorder table tbody tr td.fff:hover,#formorder table tbody tr td.gray:hover,#formorder table tbody tr td.blue:hover{background: #FFF0F0;color: #666666;}
    
    #formdiv{padding: 10px 10px;border-bottom: 1px solid #e8e8e8;}
    #formdiv input{width: 100px;}
    
    #formorder{overflow: auto;}
    #formorder table{width: 100%;}
    #formorder table thead tr th,#formorder table tbody tr td{border: 1px solid #d3d2d2;text-align: center;width: 250px;}
    #formorder table thead tr th{padding: 5px;color: #666666;font-weight: 500;background: #f0f0f0;cursor: default;}
    #formorder table tbody tr td{cursor: pointer;padding: 5px;min-width: 100px;height: 40px;overflow: hidden;}
    
    #pop-up-boxes{
        position: fixed;width: 100%;height: 100%;z-index: 20;top: 0;left: 0;display: none;
    }
    #pop-up-boxes-content{
        width: 500px;margin: 0 auto;font-size: 14px;
        border: 1px solid black;color: black;
        margin-top: 10%;background-color: #fff;border-radius: 10px;
    }
    #pop-up-boxes-title img{
		cursor: pointer;float: right;left: 0;top: 17px;width: 16px;height: 16px;margin: 3px;border: none;border-radius: 10px;
    }
    #pop-up-boxes-text{
        padding: 20px;text-align: center;color: #555555;max-height: 500px;overflow:auto;
    }
    #pop-up-boxes-text input,#pop-up-boxes-text select{padding: 3px;}
    #pop-up-boxes-text a{
        display: inline-block;
        text-align: center;
        padding: 5px 10px;
        background-color: #5bc0de;
        color: #fff;
        border-radius: 5px;
    }
    #pop-up-boxess{
        position: fixed;width: 100%;z-index: 20;top: 0;left: 0;display: none;
    }
    #pop-up-boxess-content{
        width: 500px;margin: 0 auto;font-size: 14px;
        border: 1px solid black;color: black;
        margin-top: 10%;background-color: #fff;border-radius: 10px;
    }
    #pop-up-boxess-title img{
        cursor: pointer;float: right;left: 0;top: 17px;width: 16px;height: 16px;margin: 3px;border: none;border-radius: 10px;
    }
    #pop-up-boxess-text{
        padding: 20px;text-align: center;color: #555555;max-height: 500px;overflow:auto;
    }
    #pop-up-boxess-text input,#pop-up-boxes-text select{padding: 3px;}
    #pop-up-boxess-text a{
        display: inline-block;
        text-align: center;
        padding: 5px 10px;
        background-color: #5bc0de;
        color: #fff;
        border-radius: 5px;
    }
    #edit input{border: 1px solid #d3d2d2;}
    #formorder .tables_thall tr{display: none;}
    #formorder .tables_thall tr.types_top{display: table-row;background-color: #DDDDDD;}
    #formorder .tables_thall tr.types_top td{cursor: pointer;}
    #formorder .tables_thall tr.types_top{display: table-row;background-color: #DDDDDD;}
    #formorder .tables_thall tr.types_top td{cursor: pointer;}
    #formorder table.active tr{display: table-row;}
    .ui-datepicker-trigger{display: none;}
</style>
<link rel="stylesheet" href="/public/assets/sysadmin/mylzp/css/jquery-ui.css">
<script type="text/javascript" src="/public/assets/sysadmin/mylzp/js/jquery-ui.js"></script>
<section class="vbox">
    <section class="scrollable padder">
        <ul class="breadcrumb no-border no-radius b-b b-light pull-in">
            <li><a href="#"><i class="fa fa-home"></i>酒店管理中心</a></li>
            <li><a href="#">酒店管理</a></li>
            <li><a href="#">房态管理</a></li>
        </ul>
        <div class="m-b-md">
            <h3 class="m-b-none"><span style="float:right;"></span>房态管理</h3>
        </div>
        <section class="panel panel-default">
            <header class="panel-heading">
                <i data-title="ajax to load the data." data-placement="bottom" data-toggle="tooltip" class="fa fa-info-sign text-muted" data-original-title="" title=""></i> 
                <b>房态管理</b>
                <label style="font-size: 12px;font-weight: normal;color: #FF6F6F;">---点击内容可修改状态</label>
                <a href="javascript:void(0);"><span class="gray"> </span> 已关闭</a>
                <a href="javascript:void(0);"><span class="blue"> </span> 可用</a>
                <a href="javascript:void(0);"><span class="red"> </span> 满房</a>
            </header>
            <!--<div id="formdiv">
                <form id="get_formdiv" action="<?=$this->url("hotel/info")?>" method="get">
                    <a href="<?=$statime<=strtotime(date('Y-m-d',time()))?'javascript:;':($this->url("hotel/info?statime=".date('Y-m-d',$statime-10*24*3600)))?>">《</a><input type="text" name="statime" value="<?=date('Y-m-d',$statime)?>" readonly="" class="datepickerinput" style="text-align: center;" /><a href="<?=$this->url("hotel/info?statime=".date('Y-m-d',$statime+10*24*3600))?>">》</a>
                    <a style="float: right;border: 1px solid #5bc0de;background: #5bc0de;color: #fff;padding: 2px 5px;border-radius: 3px;" href="javascript:;" onclick="setAlltype('<?=date('Y-m-d',time())?>')">一键设置房态</a>
                </form>
            </div>
            <div id="formorder">
                <table>
                    <thead>
                        <tr>
                            <th>房间/房型</th>
                            <?//时间 默认当前---10天
                            if(!empty($times)){
                                foreach($times as $k=>$v){?>
                                    <th lang="<?=$k?>" style="color: <?=$v['wday']==0?'#f39c00':''?>;" >
                                        <?=$v['date']?><br />
                                        <?
                                        if($v['time']==strtotime(date('Y-m-d',time()))){
                                            echo '<font color="#45cdec">今天</font>';
                                        }
                                        ?>
                                        <?=$pmsconfigs['wday'][$v['wday']]?>
                                    </th>
                                <?}
                            }
                            ?>
                        </tr>
                    </thead>
                </table>
                <?
                if(!empty($infoParent)){
                foreach($infoParent as $keys=>$vals){
                    $rTotal = array();
                    $timeTotal = array();
                    foreach($roomTotal as $ks=>$vs){
                        if($vs['typeId'] == $vals['id']){
                            $rTotal[]=$vs;
                            $timeTotal[]=$vs['created'];
                        }
                    }
                ?>
                <table class="types_table_<?=$keys?> <?=$keys==0?'active':''?> tables_thall">
                    <tbody>
                        <tr class="types_top" lang="<?=$keys?>">
                            <td style="background: #f0f0f0;" colspan="11"><div style="margin:0 auto;width:280px;text-align:left; "><b><?=$vals['title']?></b><label style="font-size: 12px;font-weight: normal;color: #FF6F6F;cursor:pointer;">&nbsp;房间总数 <b style="font-size:16px;"><?=$vals['roomNum']?></b>&nbsp;</label><span lang="<?=$keys==0?0:1?>" style="font-size: 12px;"><?=$keys==0?'收起∧':'展开∨'?></span><br /></div></td>
                        </tr>    
                    <?
                        if(!empty($rooms)){
                            foreach($rooms as $k=>$v){
                            if($v['parentTypeId'] == $vals['id']){
                            ?>
								<tr class="types_zi">
                                    <td style="cursor: default;">
									<?
										$star=strpos($v['title'],'(',0)+1;
										$endr=strpos($v['title'],')',0)-$star;
										if($v['zisort']>=1&&$v['zisort']<=4){
											echo substr($v['title'],$star,$endr);
										}elseif($v['zisort']>=5&&$v['zisort']<=8){
											echo substr($v['title'],$star,$endr).'(现付)';
										}
									?>
									</td>
                                    <?
                                    for($i=0;$i<10;$i++){
                                    $thisTime=$statime+$i*24*3600;
                                    ?>
										<td class="
                                            <?
                                            $kfName="";
                                            $qudao="";
                                            $infostatus='';
                                            $lateReserveTime=0;
                                            $payType='PP';
											$lateCancelTime=0;
											$guarantee='9999-F';
                                            
                                            if(!empty($roomstatus)){
                                                foreach($roomstatus as $key=>$val){
                                                    if($v['id']==$val['typeId']&&$thisTime==$val['times']){
                                                        $kfName=$val['name'];$qudao=$val['type'];
                                                        $infostatus=$val['status'];
                                                        $lateReserveTime=$val['lateReserveTime']!=''?$val['lateReserveTime']:0;
                                                        $payType=$val['payType']!=''?$val['payType']:'PP';
														$lateCancelTime=$val['lateCancelTime']!=''?$val['lateCancelTime']:0;
														$guarantee=$val['guarantee']!=''?$val['guarantee']:'9999-F';
                                                    }
                                                }
                                            }
                                            if($infostatus==''){echo "gray";}elseif($infostatus==0){echo "gray";}else{echo "blue";}
                                            ?>
                                        "
                                        <?
                                        if(!empty($rTotal) && in_array($thisTime,$timeTotal)){
                                            foreach($rTotal as $kk=>$vv){
                                                if($thisTime==$vv['created']&&$vv['total']>($vals['roomNum']-1)){
                                                ?>
                                                onclick="tagRed()" style="color: #FFF0F0;background-color: #FF6F6F;font-size: 12px;" >剩余房量 <?=$vals['roomNum']-$vv['total']?> 间
                                                <?
                                                }
                                                if(($thisTime==$vv['created']&&$vv['total']<$vals['roomNum'])){
                                                ?>
                                                onclick="status('<?=$v['id']?>','<?=date('Y-m-d',$thisTime)?>','<?=$v['title']?>','<?=($thisTime-strtotime(date('Y-m-d',time())))/24/3600?>','<?=$vals['id']?>','<?=$lateReserveTime?>','<?=$payType?>','<?=$v['zisort']?>','<?=$lateCancelTime?>','<?=$guarantee?>',this)">
                                                剩余房量 <?=$vals['roomNum']-$vv['total']?> 间
                                                <?}
                                            }
                                        }else{?>
                                        onclick="status('<?=$v['id']?>','<?=date('Y-m-d',$thisTime)?>','<?=$v['title']?>','<?=($thisTime-strtotime(date('Y-m-d',time())))/24/3600?>','<?=$vals['id']?>','<?=$lateReserveTime?>','<?=$payType?>','<?=$v['zisort']?>','<?=$lateCancelTime?>','<?=$guarantee?>',this)">
                                        剩余房量 <?=$vals['roomNum']?> 间
                                        
                                        <?}
                                        ?>
                                        </td>
                                    <?
                                    }
                                    ?>
                                </tr>
                            <?}
                            }
                        }
                        ?>
                    </tbody>
                </table>
                <?
                    }
                }
                ?>
            </div>-->
            <div style="clear: both;"></div>
        </section>
    </section>
</section>
<a href="#" class="hide nav-off-screen-block" data-toggle="class:nav-off-screen" data-target="#nav"></a>
<div id="pop-up-boxes">
    <div id="pop-up-boxes-content">
        <div id="pop-up-boxes-title"><label>&nbsp;修改房态</label><img src="/public/assets/sysadmin/mylzp/img/error.png" /></div>
        <div id="pop-up-boxes-text">
            <form action="<?=$this->url("hotel/infoStatus")?>" method="post" class="form-horizontal form-bordered form-validate" id="edit"> 
                房 型：<input type="text" name="typeName" value="" disabled="" style="background: #f0f0f0;width:300px;text-align: center;" />
                <br /><br />
                时 间：<input type="text" name="statime" readonly="" style="background: #f0f0f0;width: 80px;" />
                -
                <input type="text" name="endtime" class="" readonly="" style="background: #fff;width: 80px;" />
                <?
				if($this->partnerInfo['isbusiness']==1){?>
					<br /><br />
                    订单最晚预订时间：<select name="lateReserveTime">
                        <?
                        foreach($pmsconfigs['lateReserveTime'] as $k=>$v){?>
                            <option value="<?=$k?>"><?=$v?></option>
                        <?}
                        ?>
                    </select>
				<?}
				?>
				<span id="thInforZisort" style="display:none">
					<br /><br />
					支付类型：<select name="payType">
						<option value="FG">现付</option>
					</select><label style="color: red;font-size: 14px;margin-left: 10px;">现付(房型)：目前只针对携程</label>
					<br /><br />
					担保类型：<select name="guarantee">
						 <?
						foreach($pmsconfigs['guarantee'] as $k=>$v){?>
							<option value="<?=$k?>"><?=$v?></option>
						<?}
						?>
					</select><label style="color: red;font-size: 14px;margin-left: 10px;">现付(房型)：支持</label>
				</span>
				<br /><br />
				订单最晚取消时间：<select name="lateCancelTime">
					<?
					foreach($pmsconfigs['lateReserveTime'] as $k=>$v){?>
						<option value="<?=$k?>"><?=$v?></option>
					<?}
					?>
				</select>
                <br /><br />
                房态选择：<select name="status">
                    <option value="0">关闭</option>
                    <option value="1">可用</option>
                </select><br /><br />
                <input type="hidden" name="typeid" value="" />
                <input type="hidden" name="parentTypeId" value="" />
                <a href="javascript:void(0);" class="show_shadefrist" onclick="isedit()" >确认修改</a>
            </form>
        </div>
    </div>
</div>
<div id="pop-up-boxess">
    <div id="pop-up-boxess-content">
        <div id="pop-up-boxess-title"><label>&nbsp;一键修改房态</label><img src="/public/assets/sysadmin/mylzp/img/error.png" /></div>
        <div id="pop-up-boxess-text">
            <form action="<?=$this->url("hotel/infoStatusAll")?>" method="post" class="form-horizontal form-bordered form-validate" id="all"> 
                <?foreach($infoParent as $key=>$vals){?>
                <b><?=$vals['title']?>：</b>
                <?if(!empty($rooms)){
                    foreach($rooms as $k=>$v){
                        if($v['parentTypeId'] == $vals['id']){?>
                            <label style="font-weight: 500;margin: 5px;"><input type="checkbox" name="checkbox[]" value="<?=$v['id']?>" /><?=$v['title']?></label>
                        <?}
                    }
                }?>
                <br /><br />
                <?
                }?>
                时 间：<input type="text" name="statime" readonly="" style="background: #fff;width: 80px;" />
                -
                <input type="text" name="endtime" class="" readonly="" style="background: #fff;width: 80px;" />
                <?
				if($this->partnerInfo['isbusiness']==1){?>
					<br /><br />
                    订单最晚预订时间：<select name="lateReserveTime">
                        <?
                        foreach($pmsconfigs['lateReserveTime'] as $k=>$v){?>
                            <option value="<?=$k?>"><?=$v?></option>
                        <?}
                        ?>
                    </select>
				<?}
				?>
				<br /><br />
				支付类型：<select name="payType">
					<option value="FG">现付</option>
				</select><label style="color: red;font-size: 14px;margin-left: 10px;">现付(房型)：目前只针对携程</label>
				<br /><br />
				担保类型：<select name="guarantee">
					 <?
					foreach($pmsconfigs['guarantee'] as $k=>$v){?>
						<option value="<?=$k?>"><?=$v?></option>
					<?}
					?>
				</select><label style="color: red;font-size: 14px;margin-left: 10px;">现付(房型)：支持</label>
				<br /><br />
				订单最晚取消时间：<select name="lateCancelTime">
					<?
					foreach($pmsconfigs['lateReserveTime'] as $k=>$v){?>
						<option value="<?=$k?>"><?=$v?></option>
					<?}
					?>
				</select>
                <br /><br />
                房态选择：<select name="status">
                    <option value="0">关闭</option>
                    <option value="1">可用</option>
                </select><br /><br />
                <input type="hidden" name="typeid" value="" />
                <input type="hidden" name="parentTypeId" value="" />
                <a href="javascript:void(0);" class="show_shadefrist" onclick="isAlledit()" >确认修改</a>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript">
$('#pop-up-boxes-title img').click(function(){
    $('#pop-up-boxes').hide();
});
$('#pop-up-boxess-title img').click(function(){
    $('#pop-up-boxess').hide();
});
function isedit(){
    $("#edit").submit();
}
function isAlledit(){
    $("#all").submit();
}

//时间插件
$(function(){
    $(".datepickerinput").datepicker({
        minDate: 0,
        showMonthAfterYear: true,
        changeMonth: true,
        numberOfMonths: 1,
        showOn: "both",
        showButtonPanel:true,
        duration: 100,
    });
    $('.ui-datepicker-trigger').remove();
});
$('#get_formdiv input[name="statime"]').change(function(){
    $('#get_formdiv').submit();
});
var end=0;
//单一设置房态
function status(typeid,times,typeName,endDay,parentTypeId,lateReserveTime,payType,zisort,lateCancelTime,guarantee,obj){
	if(zisort>=5&&zisort<=8){
		$('#thInforZisort').show();
	}else{
		$('#thInforZisort').hide();
	}
    $('#edit input[name="typeName"]').val(typeName);
    $('#edit input[name="statime"]').val(times);
    $('#edit input[name="endtime"]').val('');
    $('#edit input[name="typeid"]').val(typeid);
    $('#edit input[name="parentTypeId"]').val(parentTypeId);
    
    if($.trim(obj.className) == 'blue'){
        $('#edit select[name="status"]').find("option[value=1]").attr("selected",true);
    }else{
        $('#edit select[name="status"]').find("option[value=0]").attr("selected",true);
    }
    
    $('#edit select[name="lateReserveTime"]').find("option[value="+lateReserveTime+"]").attr("selected",true);
    $('#edit select[name="payType"]').find("option[value="+payType+"]").attr("selected",true);
    $('#edit select[name="lateCancelTime"]').find("option[value="+lateCancelTime+"]").attr("selected",true);
	$('#edit select[name="guarantee"]').find("option[value="+guarantee+"]").attr("selected",true);
	
    $('#pop-up-boxes').show();
    
    //动态添加时间控件 calss
    $('#edit input[name="endtime"]').removeAttr('class');
    var now=new Date().getTime();
    $('#edit input[name="endtime"]').addClass('end_'+now);
    sdate(endDay,'end_'+now);
    $('.ui-datepicker-trigger').remove();
}
function sdate(endDay,end_className){
    $("."+end_className).datepicker({
        minDate: endDay,
        showMonthAfterYear: true,
        changeMonth: true,
        numberOfMonths: 1,
        showOn: "both",
        showButtonPanel:false,
        duration: 100,
        onSelect: function( selectedDate ) {
            $('#all input[name="endtime"]').datepicker( "option", "minDate", selectedDate );
        }
    });
}

function tagRed(){
    pub_alert_html('房间已满，不能操作！',2000);
}

$('table.tables_thall tbody tr.types_top').click(function(){
    var key=$(this).attr('lang');
    var lang=$(this).children('td').children('div').children('span').attr('lang');
    if(lang==0){
        $('table.types_table_'+key+' tbody tr.types_zi').css({"display":'none'});
        $(this).children('td').children('div').children('span').html('展开∨');
        $(this).children('td').children('div').children('span').attr('lang',1);
    }else{
        $('table.types_table_'+key+' tbody tr.types_zi').css({"display":'table-row'});
        $(this).children('td').children('div').children('span').html('收起∧');
        $(this).children('td').children('div').children('span').attr('lang',0);
    }
});

//一键设置房态
function setAlltype(times){
    $('#all input[name="statime"]').val(times);
    $('#pop-up-boxess').show();
    
    //动态添加时间控件 calss
    $('#all input[name="statime"]').removeAttr('class');
    $('#all input[name="endtime"]').removeAttr('class');
    var now=new Date().getTime();
    $('#all input[name="endtime"]').addClass('end_'+now);
    $('#all input[name="statime"]').addClass('end_'+now);
    sdate(times,'end_'+now);
    $('.ui-datepicker-trigger').remove();
}

</script>
